import javax.swing.*;
import java.awt.*;

//给button加背景图片
public class ImageButton extends JButton {
    Image im;
    String text;
    int width;
    int height;

    /**
     * 构造一个图形按钮.
     *
     * @param im 图形
     * @param text 文本
     */
    public ImageButton(Image im, String text) {
        this.im = im;
        this.width = Settings.new_game_button_w;
        this.height = Settings.new_game_button_h;
        this.setSize(width, height);
        this.text = text;
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);  //清屏
        g.drawImage(im,0,0,width, height, this);
        int x = switch (text) {
            case "New Game" -> 70;
            case "Load" -> 100;
            case "Settings" -> 80;
            default -> 40;
        };

        g.setFont(new Font(Settings.button_font, Font.BOLD, Settings.getFont_size()));     //字体 字号  字号为22，像素为32
        g.drawString(text, x, 30);
    }

}
